package cn.zwx.learn.mybatis.example.demo.interceptor;

import cn.zwx.learn.mybatis.example.croe.annotation.ZwxIntercepts;
import cn.zwx.learn.mybatis.example.croe.plugin.Interceptor;
import cn.zwx.learn.mybatis.example.croe.plugin.Invocation;
import cn.zwx.learn.mybatis.example.croe.plugin.Plugin;

import java.util.Arrays;

/**
 * 自定义插件
 * @author zhangwenxue
 */
@ZwxIntercepts("query")
public class MyPlugin implements Interceptor {


    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        String statement = (String) invocation.getArgs()[0];
        Object[] parameter = (Object[]) invocation.getArgs()[1];
        System.out.println("进入自定义插件：MyPlugin");
        System.out.println("SQL：["+statement+"]");
        System.out.println("Parameters："+ Arrays.toString(parameter));
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target,this);
    }
}
